package com.btb.adapter.controller;

import java.math.BigInteger;
import java.time.LocalDateTime;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.btb.adapter.model.MonitorTransferRequest;
import com.btb.adapter.service.EventService;

@RestController
@RequestMapping("/api")
public class EventController {
	private static final Logger LOG = LoggerFactory.getLogger(EventController.class);

	@Autowired
	private EventService eventService;

	@GetMapping("/version")
	public ResponseEntity<String> version() {
		String clientVersion = eventService.getClientVersion();
		return ResponseEntity.ok(LocalDateTime.now().toString() + " | " + clientVersion);
	}

	@GetMapping("/blockNumber")
	public BigInteger blockNumber() {
		return eventService.getBlockNumber();
	}

	@GetMapping(value = "/event/{contractAddress}/{firstBlock}/{endBlock}")
	public String e(@PathVariable String contractAddress, @PathVariable String firstBlock,
			@PathVariable String endBlock) {
		MonitorTransferRequest monitorContractRequest = new MonitorTransferRequest(contractAddress, firstBlock,
				endBlock);
		LOG.info("MonitorTransferRequest : {}", monitorContractRequest);
		eventService.contractFilter(monitorContractRequest);
		return "SUCCESS";
	}
}
